package org.xingole.jgit.lib;

import java.io.*;
/**
 * {@code ObjectId} is the specific class for a SHA-1 Java abstraction.
 * 
 * Therefore {@code ObjectId} should implements the abstract class {@code AnyObjectId}.
 * 
 * With the Git push function, the ObjectId should be serializable to apply in the network spot.
 */
public class ObjectId extends AnyObjectId implements Serializable{
    // This field is for serializable purpose
    private static final long serialVersionUID = 1L;

    // The special all-null ObjectId instance.
    private static final ObjectId ZEROID;

    // The special all-null ObjectId SHA-1 string value.
    private static final String ZEROID_STR;

    static {
        // The special all-null is the special element for ObjectID conception.
        // For these special element, we should think of these co-existing with the class.
        ZEROID = new ObjectId(0, 0, 0, 0, 0);
        ZEROID_STR = ZEROID.name();
    }

    // The special field access methods
    
    public static final ObjectId zeroId() {
        return ZEROID;
    }

    public static final boolean isId(final String id) {
        // noop implemented.
        return false;
    }

    /**
     * Convert an ObjectId into a hex string representation.
     * @param id - the id to convert. May be null.
     * @return : the hex string conversion of this id's content.
     */
    public static final String toString(final ObjectId id) {
        return id != null ? id.name() : ZEROID_STR;
    }

    /*********************************The Constructors*******************************************/
    /**
     * Construct an ObjectId from 160 bits provided in 5 words.
     * @param new_0
     * @param new_1
     * @param new_2
     * @param new_3
     * @param new_4
     */
    public ObjectId(int new_0, int new_1, int new_2, int new_3, int new_4) {
        w0 = new_0;
        w1 = new_1;
        w2 = new_2;
        w3 = new_3;
        w4 = new_4;
    }

    /**
     * <p>Initialize this instance by copying another existing ObjectId.</p>
     * Notes:
     * <p>
     * This constructor is mostly useful for subclasses who want to extend an 
     * ObjectId with more properties, but initialize from an existing ObjectId 
     * instance acquired by other means.</p>
     * 
     * @param src - another already parsed ObjectId to copy the value out of the field.
     */
    protected ObjectId(final AnyObjectId src) {
        w0 = src.w0;
        w1 = src.w1;
        w2 = src.w2;
        w3 = src.w3;
        w4 = src.w4;
    }
}
